package com.lvxtech.gateway.controller;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.lvxtech.gateway.service.RouteService;

import reactor.core.publisher.Flux;


@RestController
public class RouteController {
	
	@Autowired
    RouteService routeService;
	@Autowired
	RouteDefinitionLocator routeDefinitionLocator;
	
//	@PostMapping("/addRoute")
	public Flux<RouteDefinition> addRoute(@RequestBody RouteDefinition route) {
		routeService.save(route);
		return routeDefinitionLocator.getRouteDefinitions();
	}
	
	
	@GetMapping("/getRoutes")
	public Flux<RouteDefinition> getRoutes() {
		return routeDefinitionLocator.getRouteDefinitions();
	}
	
	
	@GetMapping("/getRedisRoutes")
	public Flux<RouteDefinition> getRedisRoutes() {
		return Flux.fromIterable(routeService.getRouteDefinitions());
	}

}
